home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / plan / src / yearmenu.c < prev   
C/C++ Source or Header  |  1994-08-01  |  6KB  |  215 lines

  1. /*
  2.  * year menu widgets.
  3.  *
  4.  *    destroy_year_menu()        Destroy the year window an its
  5.  *                    contents
  6.  *    create_year_menu()        Create a year calendar for curr_year
  7.  *                    and put a year view into it
  8.  *    destroy_year_view()        Destroy year view, to make room for
  9.  *                    another view in the mainwindow
  10.  *    create_year_view(parent)    Create a form widget for the year
  11.  *                    view, and everything in it.
  12.  */
  13.  
  14. #ifndef MIPS
  15. #include <stdlib.h>
  16. #endif
  17. #include <stdio.h>
  18. #include <time.h>
  19. #include <varargs.h>
  20. #include <Xm/Xm.h>
  21. #include <Xm/DialogS.h>
  22. #include <Xm/Form.h>
  23. #include <Xm/Frame.h>
  24. #include <Xm/RowColumn.h>
  25. #include <Xm/LabelP.h>
  26. #include <Xm/ArrowBP.h>
  27. #include <Xm/ArrowBG.h>
  28. #include <Xm/PushBP.h>
  29. #include <Xm/PushBG.h>
  30. #include <Xm/Text.h>
  31. #include <Xm/ScrolledW.h>
  32. #include <Xm/DrawingA.h>
  33. #include <Xm/Protocols.h>
  34. #include "cal.h"
  35.  
  36. static void done_callback(), year_cal_callback();
  37. extern void help_callback();
  38. extern time_t length_of_month();
  39.  
  40. extern Display        *display;    /* everybody uses the same server */
  41. extern GC        gc;        /* everybody uses this context */
  42. extern Widget        toplevel;    /* top-level shell */
  43. extern struct mainmenu    mainmenu;    /* all important window widgets */
  44. extern struct config    config;        /* global configuration data */
  45. extern struct list    *mainlist;    /* list of all schedule entries */
  46. extern XFontStruct    *font[NFONTS];    /* fonts: FONT_* */
  47. extern Pixel        color[NCOLS];    /* colors: COL_* */
  48.  
  49. static BOOL        have_shell;    /* year window is being displayed */
  50. static Widget        shell;
  51. static BOOL        have_view;    /* <all> is a valid widget */
  52. static Widget        all;        /* the form that contains everything */
  53.  
  54.  
  55. /*
  56.  * destroy the year menu. Remove it from the screen, and destroy its widgets.
  57.  * It's too much trouble to keep them for next time.
  58.  */
  59.  
  60. destroy_year_menu()
  61. {
  62.     if (have_shell) {
  63.         XtPopdown(shell);
  64.         XTDESTROYWIDGET(shell);
  65.         have_shell = FALSE;
  66.         mainmenu.yearcal = 0;
  67.     }
  68. }
  69.  
  70.  
  71. /*
  72.  * create the year menu.
  73.  * There should be buttons for Quit, next/prev year, next/prev 6 months.
  74.  */
  75.  
  76. create_year_menu()
  77. {
  78.     Arg            args[5];
  79.     int            n;
  80.     Atom            closewindow;
  81.     BOOL            had_view = have_view;
  82.  
  83.     if (have_shell) {
  84.         XtPopup(shell, XtGrabNone);
  85.         XRaiseWindow(display, XtWindow(shell));
  86.         draw_year_calendar();
  87.         return;
  88.     }
  89.     n = 0;
  90.     XtSetArg(args[n], XmNdeleteResponse,    XmDO_NOTHING);        n++;
  91.     XtSetArg(args[n], XmNiconic,        False);            n++;
  92.     shell = XtAppCreateShell("Year Calendar", "plan",
  93.             applicationShellWidgetClass, display, args, n);
  94. #    ifdef EDITRES
  95.     XtAddEventHandler(shell, (EventMask)0, TRUE, 
  96.              _XEditResCheckMessages, NULL);
  97. #    endif
  98.     set_icon(shell, 0);
  99.  
  100.     create_year_view(shell);
  101.  
  102.     XtPopup(shell, XtGrabNone);
  103.     closewindow = XmInternAtom(display, "WM_DELETE_WINDOW", False);
  104.     XmAddWMProtocolCallback(shell, closewindow,
  105.                     done_callback, (XtPointer)shell);
  106.     have_shell = TRUE;
  107.     have_view  = had_view;
  108. }
  109.  
  110.  
  111. /*
  112.  * destroy the contents of the year view. This is used when the year view is
  113.  * in the mainwindow, not in its own window, and another view is requested.
  114.  */
  115.  
  116. destroy_year_view()
  117. {
  118.     if (have_view) {
  119.         XTDESTROYWIDGET(all);
  120.         have_view = FALSE;
  121.     }
  122. }
  123.  
  124.  
  125. /*
  126.  * create a form and all year widgets in that form. This is called from two
  127.  * places: from create_year_menu above if a year view in its own window is
  128.  * created, and from caldraw.c if a year view is to be displayed in the
  129.  * mainwindow.
  130.  */
  131.  
  132. create_year_view(parent)
  133.     Widget            parent;
  134. {
  135.     Arg            args[15];
  136.     int            n;
  137.     Widget            scroll;
  138.  
  139.     all = XtCreateWidget("yearform", xmFormWidgetClass,
  140.             parent, NULL, 0);
  141.     XtAddCallback(all, XmNhelpCallback, help_callback, (XtPointer)"year");
  142.  
  143.     n = 0;
  144.     XtSetArg(args[n], XmNtopAttachment,    XmATTACH_FORM);        n++;
  145.     XtSetArg(args[n], XmNbottomAttachment,    XmATTACH_FORM);        n++;
  146.     XtSetArg(args[n], XmNleftAttachment,    XmATTACH_FORM);        n++;
  147.     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);        n++;
  148.     XtSetArg(args[n], XmNtopOffset,        8);            n++;
  149.     XtSetArg(args[n], XmNbottomOffset,    8);            n++;
  150.     XtSetArg(args[n], XmNleftOffset,    8);            n++;
  151.     XtSetArg(args[n], XmNrightOffset,    8);            n++;
  152.     XtSetArg(args[n], XmNwidth,        2*config.year_margin+
  153.                         4*config.yearbox_xs*7+
  154.                         3*config.year_gap +4);    n++;
  155.     XtSetArg(args[n], XmNheight,        2*config.year_margin+
  156.                         1*config.year_title +
  157.                         3*config.yearbox_ys*8+
  158.                         3*config.year_gap +4);    n++;
  159.     XtSetArg(args[n], XmNscrollingPolicy,    XmAUTOMATIC);        n++;
  160.     scroll = XtCreateWidget("scroll", xmScrolledWindowWidgetClass,
  161.             all, args, n);
  162.  
  163.     n = 0;
  164.     XtSetArg(args[n], XmNwidth,        2*config.year_margin+
  165.                         4*config.yearbox_xs*7+
  166.                         3*config.year_gap);    n++;
  167.     XtSetArg(args[n], XmNheight,        2*config.year_margin+
  168.                         1*config.year_title +
  169.                         3*config.yearbox_ys*8+
  170.                         3*config.year_gap);    n++;
  171.     mainmenu.yearcal = XtCreateWidget("yearcal", xmDrawingAreaWidgetClass,
  172.             scroll, args, n);
  173.     XtAddCallback(mainmenu.yearcal, XmNinputCallback,
  174.                     year_cal_callback, (XtPointer)NULL);
  175.     XtAddCallback(mainmenu.yearcal, XmNexposeCallback,
  176.                     year_cal_callback, (XtPointer)NULL);
  177.  
  178.     XtManageChild(mainmenu.yearcal);
  179.     XtManageChild(scroll);
  180.     XtManageChild(all);
  181. }
  182.  
  183.  
  184. /*-------------------------------------------------- callbacks --------------*/
  185. /*
  186.  * All of these routines are direct X callbacks.
  187.  */
  188.  
  189. /*ARGSUSED*/
  190. static void done_callback(widget, item, data)
  191.     Widget                widget;
  192.     int                item;
  193.     XmToggleButtonCallbackStruct    *data;
  194. {
  195.     destroy_year_menu();
  196. }
  197.  
  198.  
  199. /*ARGSUSED*/
  200. static void year_cal_callback(w, data, info)
  201.     Widget                w;
  202.     XtPointer            data;
  203.     XmDrawingAreaCallbackStruct    *info;
  204. {
  205.     if (info->reason == XmCR_INPUT && info->event->xany.type ==ButtonPress)
  206.         clicked_year_calendar(info->event->xbutton.x,
  207.                       info->event->xbutton.y);
  208.     else if (info->reason == XmCR_EXPOSE) {
  209.         XEvent dummy;
  210.         while (XCheckWindowEvent(display, info->window, ExposureMask,
  211.                                 &dummy));
  212.         draw_year_calendar();
  213.     }
  214. }
  215.